package c1761;

import java.util.Scanner;
 
public class I {
    static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }
 
    static class Fraction {
        int up, down;
 
        public Fraction(int up, int down) {
            this.up = up;
            this.down = down;
            rationalize();
        }
 
        private void rationalize() {
            int g = gcd(up, down);
            down /= g;
            up /= g;
        }
 
        public Fraction add(Fraction b) {
            int up = this.up * b.down + this.down * b.up;
            int down = this.down * b.down;
            return new Fraction(up, down);
        }
 
        @Override
        public String toString() {
            return String.format("%d %d", up, down);
        }
    }
 
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int T = cin.nextInt();
        while (T-- > 0) {
            Fraction a = new Fraction(cin.nextInt(), cin.nextInt());
            Fraction b = new Fraction(cin.nextInt(), cin.nextInt());
            System.out.println(a.add(b));
        }
    }
}